﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ArgusPCLib.Threading.Collections
{
	public interface ISynchronizedList<T> : ISynchronizedCollection<T>, IList<T>
	{
	}

	public abstract class SynchronizedListBase<T> : SynchronizedCollectionBase<T>, ISynchronizedList<T>
	{
		public SynchronizedListBase()
			: base() { }

		public SynchronizedListBase(object syncRoot)
			: base(syncRoot) { }

		protected abstract T ItemGetCore(int index);
		protected abstract void ItemSetCore(int index, T item);
		T IList<T>.this[int index]
		{
			get { return this.ItemGetCore(index); }
			set { this.ItemSetCore(index, value); }
		}

		protected abstract void RemoveAtCore(int index);
		void IList<T>.RemoveAt(int index)
		{
			lock (this.SyncRoot) { this.RemoveAtCore(index); }
		}

		protected abstract int IndexOfCore(T item);
		int IList<T>.IndexOf(T item)
		{
			lock (this.SyncRoot) { return this.IndexOfCore(item); }
		}

		protected abstract void InsertCore(int index, T item);
		void IList<T>.Insert(int index, T item)
		{
			lock (this.SyncRoot) { this.InsertCore(index, item); }
		}
	}
}
